import 'babel-polyfill'
import _ from 'lodash'
import notie from 'notie'
import 'notie/dist/notie.css'
import swal from 'sweetalert'
import 'sweetalert/dist/sweetalert.css'
import Vue from 'vue'
import VueRouter from 'vue-router'
import configRouter from './router'
import App from './app'
import store from './vuex/store'
import { sync } from 'vuex-router-sync'
import filter from './filter'
import directive from './directive'
import helper from './helper'
import VueDragableFor from 'vuedragablefor'
import infiniteScroll from 'vue-infinite-scroll'
import moment from 'moment'
import bluebird from 'bluebird'
import VueClickoutside from 'vue-clickoutside'

    
window.swal = swal
window.swalConfirm = helper.confirm

window.bluebird = bluebird

Vue.use(infiniteScroll)
Vue.use(VueDragableFor)

window.notie = window.noti = notie
window.notieError = str => {
  notie.alert(3, str, 2)
}
window.notieSuccess = str => {
  notie.alert(1, str, 2)
}
window.catchError = helper.catchError
window.StatusError = helper.StatusError
window.onunhandledrejection = helper.uncaughtHandler

moment.locale('zh-cn')
Vue.use({
  install: Vue => {
    Vue.prototype._ = window._ = _
    Vue.prototype.moment = window.moment = moment
    Vue.prototype.helper = helper
  }
})


filter(Vue)
directive(Vue)
Vue.use(VueClickoutside)
Vue.use(VueRouter)
const router = new VueRouter({
  history: true,
  saveScrollPosition: true,
  transitionOnLoad: true,
})

configRouter(router)

Vue.config.debug = process.env.DEBUG_MODE
sync(store, router)

router.start(App, 'app')



// if (!process.env.DEBUG_MODE) {
//   window.onbeforeunload = () => {
//     return '确定要离开页面吗？'
//   }
// }

window.router = router

try {
  window.__VUE_DEVTOOLS_GLOBAL_HOOK__.Vue = Vue
} catch (err) {
  console.log('VUE DEV', err)
}
